﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace IT_Pro.Class
{
    class CV_GhiNhanYeuCau
    {
        private int _id;

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        
        private DateTime _ngayYC;


        public DateTime NgayYC
        {
            get { return _ngayYC; }
            set { _ngayYC = value; }
        }
        private string _nguoiYC;

        public string NguoiYC
        {
            get { return _nguoiYC; }
            set { _nguoiYC = value; }
        }
        private string _nguoiTH;

        public string NguoiTH
        {
            get { return _nguoiTH; }
            set { _nguoiTH = value; }
        }
        private string _nguoiDuyet;

        public string NguoiDuyet
        {
            get { return _nguoiDuyet; }
            set { _nguoiDuyet = value; }
        }
        private int _loaiYC;

        public int LoaiYC
        {
            get { return _loaiYC; }
            set { _loaiYC = value; }
        }
        private string _noiDung;

        public string NoiDung
        {
            get { return _noiDung; }
            set { _noiDung = value; }
        }
        private int _suLy;

        public int SuLy
        {
            get { return _suLy; }
            set { _suLy = value; }
        }
        private int _apDung;

        public int ApDung
        {
            get { return _apDung; }
            set { _apDung = value; }
        }
        private DateTime _ngayKT;

        public DateTime NgayKT
        {
            get { return _ngayKT; }
            set { _ngayKT = value; }
        }
        private int _thucHien;

        public int ThucHien
        {
            get { return _thucHien; }
            set { _thucHien = value; }
        }
        private string _ghiChu;

        public string GhiChu
        {
            get { return _ghiChu; }
            set { _ghiChu = value; }
        }
        private DateTime _ngBDYC;

        public DateTime NgBDYC
        {
            get { return _ngBDYC; }
            set { _ngBDYC = value; }
        }
        private DateTime _ngKTYC;

        public DateTime NgKTYC
        {
            get { return _ngKTYC; }
            set { _ngKTYC = value; }
        }

        public static DataTable LoadDanhSachSuLy()
        {
            string procName = "cv_LoadDanhSachSuLy";
            return DataServices.ExcuteProcedureGetTable(procName, null);
        }
        public static DataTable LoadLoaiYeuCau()
        {
            string procName = "cv_LoadLoaiYeuCau";
            return DataServices.ExcuteProcedureGetTable(procName, null);
        }
        public static DataTable LoadLoaiApDung()
        {
            string procName = "cv_LoadLoaiApDung";
            return DataServices.ExcuteProcedureGetTable(procName, null);
        }

        public int ThemGhiNhanYeuCauIT()
        {
            string procName = "cv_ThemGhiNhanYeuCauIT";
            SqlParameter[] parameters = new SqlParameter[9];
            parameters[0] = new SqlParameter("@ngayyc",NgayYC);
            parameters[1] = new SqlParameter("@nguoiyc", NguoiYC);
            parameters[2] = new SqlParameter("@nguoith", NguoiTH);
            parameters[3] = new SqlParameter("@nguoiduyet", NguoiDuyet);
            parameters[4] = new SqlParameter("@loaiyc", LoaiYC);
            parameters[5] = new SqlParameter("@noidung", NoiDung);
            parameters[6] = new SqlParameter("@apdung", ApDung);
            parameters[7] = new SqlParameter("@ngaykt", NgayKT);
            parameters[8] = new SqlParameter("@ghichu ", GhiChu);
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;   
        }

        public DataTable LoaiDSYC()
        {
            string procName = "cv_HienThiDanhSachYC";
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@suly", SuLy);
            parameters[1] = new SqlParameter("@ngbd", NgBDYC);
            parameters[2] = new SqlParameter("@ngaykt ", NgKTYC);
            return DataServices.ExcuteProcedureGetTable(procName, parameters);
        }

        public int SuLyYeuCau()
        {
            string procName = "cv_CapNhatGhiNhanYeuCauIT";
            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@id", Id);
            parameters[1] = new SqlParameter("@suly", SuLy);
            parameters[2] = new SqlParameter("@nguoith", NguoiTH);
            parameters[3] = new SqlParameter("@ngayhoanthanh", DateTime.Now);
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }

        public DataTable LichKetThucYeuCau()
        {
            string procName = "cv_LichHenKetThucYC";
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@thuchien ", ThucHien);
            return DataServices.ExcuteProcedureGetTable(procName, parameters);
        }

        public int ThucHienKetThucYC()
        {
            string procName = "cv_KetThucHanYeuCauIT";
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@id", Id);
            parameters[1] = new SqlParameter("@thuchien", ThucHien);
            parameters[2] = new SqlParameter("@ngayhoanthanh", DateTime.Now); 
            int i = DataServices.ExcuteProcedureWithReturn(procName, parameters);
            return i;
        }

        public static string[] KiemTraLichThucHien()
        {
            
            string procName = "kt_KiemTraLichThucHien";
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@ngaylamviec ", DateTime.Now);
            DataTable dt= DataServices.ExcuteProcedureGetTable(procName, parameters);
            if (dt.Rows.Count > 0)
            {
                string[] strThongBao = new string[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strThongBao[i] = " *** Yêu cầu IT số: " + dt.Rows[0]["ID"].ToString() + "\r\n Đã hết hạn ngày : " + dt.Rows[0]["NgayKetThuc"].ToString() + " \r\n Nội dung: " + dt.Rows[0]["NoiDung"].ToString() + " \r\n ";
                }
                return strThongBao;
            }
            else
            {
                return null;
            }

        }

       
    }
}
